
// <copyright file="AppDomainHelper.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The app domain helper.
// </summary>

namespace SubhadraSolutions.Sharp.Utils
{
    using System;
    using System.Diagnostics;

    /// <summary>
    /// The app domain helper.
    /// </summary>
    public static class AppDomainHelper
    {
        #region Constructors and Finalizers

        /// <summary>
        /// Initializes static members of the <see cref="AppDomainHelper"/> class.
        /// </summary>
        static AppDomainHelper()
        {
            AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;
        }

        #endregion Constructors and Finalizers

        #region Public Events

        /// <summary>
        /// The assembly load.
        /// </summary>
        public static event EventHandler<AssemblyLoadEventArgs> AssemblyLoad;

        #endregion Public Events

        #region Methods

        /// <summary>
        /// The current domain_ assembly load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
        {
            Delegate[] invocationList = AssemblyLoad.GetInvocationList();
            foreach (Delegate t in invocationList)
            {
                try
                {
                    t.DynamicInvoke(sender, args);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }
            }
        }

        #endregion Methods
    }
}